<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8"/>
	<meta name="keywords" content="sort, pattern sort"/>
	<link rel="stylesheet" href="../../Shared/sty/standard.css"/>
	<script defer src="../../Shared/js/toc.js"></script>
	
	<title>Sort lines using specific pattern in CotEditor on Mac</title>
</head>

<body>
<a name="howto_pattern_sort"></a>

<h1>Sort lines using specific pattern in CotEditor on Mac</h1>

<p>With Sort by Pattern, you can sort selected lines by specifying the way to compare.</p>


<section>
<ol>
	<li><p>In the CotEditor app <img class="appicon" srcset="../../Shared/gfx/icon_32x32@2x.png 2x" alt=""/> on your Mac, open a document.</p></li>
	<li><p>Choose Text &gt; Lines &gt; Sort by Pattern.</p></li>
	<li><p>Configure the sorting rules in the dialog.</p></li>
	<li><p>Click Sort.</p></li>
</ol>

<p>The normal Sort command in the Text &gt; Lines menu is the same as sorting “Entire line” with “Ignore case” and “Respect language rules” options on.</p>
</section>


<section>
<h2>Configure the sorting rules</h2>

<h3>Sample</h3>

<p>In this field, you can test which part in a line is used for sort comparison.</p>


<h3>Sort key</h3>
<p>Specify the part in lines to compare on sort.</p>

<dl>
	<dt>Entire line</dt>
	<dd>Compare entire lines.</dd>
	
	<dt>Column</dt>
	<dd>Treat lines as CSV (character-separated values) format and use the specific column for comparison. Whitespace around the separator is just ignored.</dd>
	<dd><table>
		<thead>
			<tr><th>Option</th><th>Description</th></tr>
		</thead>
		<tbody>
			<tr><td>Delimiter</td><td>The character separating each column. You can use escape sequences such as <code>\t</code> for the tabular character. A comma is used when this field is blank.</dd>
			<tr><td>Position</td><td>The number of the column to use as the sort key. The column count starts at 1.</td></tr>
		</tbody>
	</table></dd>

	<dt>Regular expression</dt>
	<dd>Specify the part to compare with the regular expression.</dd>
	<dd><table>
		<thead>
			<tr><th>Option</th><th>Description</th></tr>
		</thead>
		<tbody>
			<tr><td>Pattern</td><td>The regular expression pattern to extract the part to compare.</dd>
			<tr><td>Ignore case</td><td>Whether ignore the character case by extracting the regular expression pattern. This option is used only for the sort key extraction. To set case-insensitive state for the sort phase, set in the sort option bellow.</td></tr>
			<tr><td>Use captured group</td><td>The part in matches to use as the sort key. The entire match is used when this option is unselected.</td></tr>
		</tbody>
	</table></dd>
</dl>


<h3>Sort options</h3>
<p>Options to control behavior on comparing sort keys.</p>

<table>
	<thead>
		<tr><th>Option</th><th>Description</th></tr>
	</thead>
	<tbody>
		<tr><td>Ignore case</td><td>Ignore character case on sort.</td></tr>
		<tr><td>Respect language rules</td><td>Fuzzily sort respecting the current language setting. For example, ignoring trivial differences such as character widths or diacritical marks.</td></tr>
		<tr><td>Treat numbers as numeric value</td><td>Numbers within the sort keys are compared as numeric value. (for example, file12 &gt; file5)</td></tr>
		<tr><td>Keep the first line at the top</td><td>Ignore the first line by sorting.</td></tr>
		<tr><td>In descending order</td><td>Sort results in descending order.</td></tr>
	</tbody>
</table>
</section>


<section id="cf">
	<h2>See also</h2>
	<ul>
		<li><a href="about_regex.html">Use the regular expression in CotEditor on Mac</a></li>
	</ul>
</section>

</body>
</html>
